package com.mtsmda.designPattern.flyweight;

import java.util.HashMap;
import java.util.Map;

public class ShapeFactory {

	private static final Map<ShapeType, Shape> shapes = new HashMap<>();

	public static Shape getShape(ShapeType shapeType) {
		Shape shape = shapes.get(shapeType);
		if (shape == null) {
			if (shapeType.equals(ShapeType.LINE)) {
				shape = new Line();
			} else if (shapeType.equals(ShapeType.OVAL_FILL)) {
				shape = new Oval(true);
			} else if (shapeType.equals(ShapeType.OVAL_NOFILL)) {
				shape = new Oval(false);
			}
			shapes.put(shapeType, shape);
		}
		return shape;
	}

	enum ShapeType {
		OVAL_FILL, OVAL_NOFILL, LINE
	};
}